package net.xxcl.exam.service;

import java.util.List;
import net.xxcl.exam.mapper.KemuMapper;
import net.xxcl.exam.pojo.Criteria;
import net.xxcl.exam.pojo.Kemu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional()
public class KemuService{
    @Autowired
    private KemuMapper kemuMapper;

    private static final Logger logger = LoggerFactory.getLogger(KemuService.class);

    @Transactional(readOnly = true)
    public int countByExample(Criteria example) {
        int count = this.kemuMapper.countByExample(example);
        logger.debug("count: {}", count);
        return count;
    }

    @Transactional(readOnly = true)
    public Kemu selectByPrimaryKey(Integer id) {
        return this.kemuMapper.selectByPrimaryKey(id);
    }

    @Transactional(readOnly = true)
    public List<Kemu> selectByExample(Criteria example) {
        return this.kemuMapper.selectByExample(example);
    }

    public int deleteByPrimaryKey(Integer id) {
        return this.kemuMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKeySelective(Kemu record) {
        return this.kemuMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByPrimaryKey(Kemu record) {
        return this.kemuMapper.updateByPrimaryKey(record);
    }

    public int deleteByExample(Criteria example) {
        return this.kemuMapper.deleteByExample(example);
    }

    public int updateByExampleSelective(Kemu record, Criteria example) {
        return this.kemuMapper.updateByExampleSelective(record, example);
    }

    public int updateByExample(Kemu record, Criteria example) {
        return this.kemuMapper.updateByExample(record, example);
    }

    public int insert(Kemu record) {
        return this.kemuMapper.insert(record);
    }

    public int insertSelective(Kemu record) {
        return this.kemuMapper.insertSelective(record);
    }

    /**
     * 删除科目
     * @param ids
     * @return
     */
    public int deleteKemu(String ids) {
        String[] str = ids.split(",");
        for(String id:str){
            this.kemuMapper.deleteByPrimaryKey(Integer.parseInt(id));
        }
        return str.length;
    }
}